﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Statistics : System.Web.UI.Page
{
    bussiness bus;
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            if (Session["admin"] != null)
            {
                load_data();
                load_TransactionToday();
                //load_Customer();
                load_TypeEcardInMonth();
                load_top5EcardSentInMonth();
                
            }
            else
            {
                Response.Redirect("blankAdmin.aspx");
            }
           
        }
    }
    private void load_data()
    {
        bus = new bussiness();
        grvCount.DataSource = bus.getView_Statistics_count();
        grvCount.DataBind();
        lblTotalCount.Text = bus.getCount_View_Statistics_count().ToString();
        lblToday.Text = bus.getSoLanGuiCardToDay().ToString();
    }
    private void load_TransactionToday()
    {
        bus = new bussiness();
        grvTransactionToday.DataSource = bus.getview_StatisticTransactionByToday();
        grvTransactionToday.DataBind();
        lblTransactionToday.Text = bus.getview_numberOfSentMailInToday().ToString();
    }
    private void load_TypeEcardInMonth()
    {
        bus = new bussiness();
        grvTypeEcardInMonth.DataSource = bus.getview_TypeEcardSentInMonth();
        grvTypeEcardInMonth.DataBind();
    }
    private void load_top5EcardSentInMonth()
    {
        bus = new bussiness();
        grvEcardSentInMonth.DataSource = bus.getview_EcardSentInMonth();
        grvEcardSentInMonth.DataBind();
    }
    //private int count_subcrible = 0;
    //private int count_normal = 0;
    //private int count_total = 0;

    //private void load_Customer()
    //{
    //    bus = new bussiness();
    //    List<Customer> lstCustomer = bus.getAllCustomer();
    //    grvCustomer.DataSource = lstCustomer;
    //    grvCustomer.DataBind();
    //    foreach (Customer c in lstCustomer)
    //    {
    //        count_total++;
    //        if (c.Status == "subcrible")
    //        {
    //            count_subcrible++;
    //        }
    //        if (c.Status == "normal")
    //        {
    //            count_normal++;
    //        }
    //    }
    //    lblTotalCustumer.Text = count_total.ToString();
    //    lblCustomerNormal.Text = count_normal.ToString();
    //    lblCustomerSubcribe.Text = count_subcrible.ToString();
    //}
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        load_data();
    }
   
    protected void grvCount_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grvCount.PageIndex = e.NewPageIndex;
        load_data();
    }
    //protected void grvCustomer_PageIndexChanging(object sender, GridViewPageEventArgs e)
    //{
    //    grvCustomer.PageIndex = e.NewPageIndex;
       
    //}
    protected void btnUpdateTypeEcard_Click(object sender, EventArgs e)
    {
        load_TypeEcardInMonth();
    }
    protected void grvTypeEcardInMonth_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grvTypeEcardInMonth.PageIndex = e.NewPageIndex;
        load_TypeEcardInMonth();
    }
    protected void grvEcardSentInMonth_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grvEcardSentInMonth.PageIndex = e.NewPageIndex;
        load_top5EcardSentInMonth();
    }
    protected void btnUpdateTop5_Click(object sender, EventArgs e)
    {
        load_top5EcardSentInMonth();
    }
}